class Solution {
public:
    int breakfastNumber(vector<int>& staple, vector<int>& drinks, int x) {
        sort(staple.begin(),staple.end());
        sort(drinks.begin(),drinks.end());
        int i=0;
        int j=drinks.size()-1;
        long long ans=0;

        while(i<staple.size() && j>=0)
        {
            int sum=staple[i]+drinks[j];
            if(sum<=x)
            {
                i++;//已经枚举完i的所有数，继续枚举下一个i
                ans+=j+1;//如果加上j依旧<=x，说明加上j前面的所有数都可以，而j是从0开始，所有要+1
                ans%=1000000007;;
            }
            else
            {
                j--;
            }
        }
        return ans %1000000007;
    }
};